package com.scf.fruit.business.order.bo;

import com.scf.fruit.business.order.po.OrderInfoReq;
import com.scf.fruit.enums.ExceptionCodeEnum;
import com.scf.fruit.order.OrderInfoDto;
import com.scf.fruit.order.OrderInfoService;
import com.scf.fruit.util.ResponseVo;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;

/**
 * @author : 孙超飞
 * @title :
 * @description :
 * @copyright :
 * @date : 2018-05-18 17:55
 */
@Component
public class OrderBo {
    @Resource
    private OrderInfoService orderInfoService;

    public ResponseVo saveOrder(Long userId, OrderInfoReq req){
        ResponseVo res=new ResponseVo();
        OrderInfoDto orderInfoDto=new OrderInfoDto();
        orderInfoDto.setDetail(req.getDetail());
        orderInfoDto.setAddressId(req.getAddressId());
        orderInfoDto.setUserId(userId);
        boolean b = orderInfoService.saveOrder(orderInfoDto, req.getList());
        if(!b){
            return new ResponseVo(ExceptionCodeEnum.EX_ORDER_ERROR.getValue(),ExceptionCodeEnum.EX_ORDER_ERROR.getMsg());
        }

        return res;
    }

    public ResponseVo deleteOrderDetail(Long id,Long userId){
        ResponseVo res=new ResponseVo();
        boolean b = orderInfoService.deleteOrderDetail(id, userId);
        if(!b){
            return new ResponseVo(ExceptionCodeEnum.EX_ORDER_ERROR.getValue(),ExceptionCodeEnum.EX_ORDER_ERROR.getMsg());
        }
        return res;
    }

    public ResponseVo deleteOrder(Long id,Long userId){
        ResponseVo res=new ResponseVo();
        boolean b = orderInfoService.deleteOrder(id, userId);
        if(!b){
            return new ResponseVo(ExceptionCodeEnum.EX_ORDER_ERROR.getValue(),ExceptionCodeEnum.EX_ORDER_ERROR.getMsg());
        }
        return res;
    }
}
